package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.ScrollShop;
import com.sc.nft.mapper.ScrollShopMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 卷轴商店表(sc_scroll_shop)数据DAO
 *
 * @author zxy
 * @since 2024-09-04 02:15:00
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class ScrollShopDao extends ServiceImpl<ScrollShopMapper, ScrollShop> {


    public ScrollShop getByUserId(Long userId) {
        return lambdaQuery().eq(ScrollShop::getUserId, userId).one();
    }
    public Page<ScrollShop> findBykeyWord(String keyword,Page page) {
        return lambdaQuery().eq(ScrollShop::getStatus,true).eq(ScrollShop::getFreezeStatus,false).and(l->l.like(ScrollShop::getShopName, keyword).or().eq(ScrollShop::getShopNum,keyword)).page(page);
    }

    public boolean checkNameExists(String name) {
        return lambdaQuery().eq(ScrollShop::getShopName, name).count()>0;
    }

    public void updateShopName(Long id, String name) {
        lambdaUpdate().set(ScrollShop::getShopName, name).eq(ScrollShop::getId, id).update();
    }

    public void updateFreezeStatus(Long id, boolean status) {
        lambdaUpdate().set(ScrollShop::getFreezeStatus, status).eq(ScrollShop::getId, id).update();
    }

    public void addDealCount(Long id,Integer count) {
        UpdateWrapper<ScrollShop> wrapper = new UpdateWrapper<>();
        wrapper.setSql("deal_count=deal_count+1");
        wrapper.eq("id", id);
        update(wrapper);

    }
}